﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PhysicalExamination5.Model.SystemSetting
{
    public class CaiDanRuleClass
    {
        public int iRuleId { get; set; }
        public int iShangJiRuleId {  get; set; }
        [Required(ErrorMessage ="规则类型是必填项！")]
        public string strType { get; set; }
        [Required(ErrorMessage ="路由标题是必填项！")]
        public string strTitle { get; set; }
        [Required(ErrorMessage ="路由路径是必填项！")]
        public string strPath { get; set; }
        [Required(ErrorMessage ="路由名称是必填项！")]
        public string strName { get; set; }
        [Required(ErrorMessage ="图标是必填项！")]
        public string strIcon { get; set; }
        public string strRedirect { get; set; }
        public string strComponent { get; set; }
        [DefaultValue(false)]
        public bool isLink { get; set; }
        [DefaultValue(false)]
        public bool isHide { get; set; }
        [DefaultValue(false)]
        public bool isFull { get; set; }
        [DefaultValue(false)]
        public bool isAffix { get; set; }
        public bool isKeepAlive { get; set; }
        public bool Validate(out string strFanHuiZhi)
        {
            bool isSuccess = true;
            strFanHuiZhi = "";
            List<string> missingKeys = new List<string>();
            if (strType == "菜单项")
            {
                if (string.IsNullOrEmpty(strComponent))
                {
                    missingKeys.Add("组件");
                }
                if (iShangJiRuleId == 0)
                {
                    missingKeys.Add("上级菜单ID");
                }
            }

            if (missingKeys.Count > 0)
            {
                isSuccess = false;
                strFanHuiZhi = string.Join("、", missingKeys) + "是必填项！";
            }
            return isSuccess;
        }
    }

    public class RuLeClass
    {
        public int iRuleId { get; set; }
        public int iShangJiRuleId { get; set; }
        public string strType { get; set; }
        public string path { get; set; }
        public string name { get; set; }
        public string redirect { get; set; }
        public string component { get; set; }
        public Meta meta { get; set; }
        public List<Children> children { get; set; }
    }

    public class Children
    {
        public int iRuleId { get; set; }
        public int iShangJiRuleId { get; set; }
        public string strType { get; set; }
        public string path { get; set; }
        public string name { get; set; }
        public string component { get; set; }
        public Meta meta { get; set; }
    }
    public class Meta
    {
        public string icon { get; set; }
        public string title { get; set; }
        [DefaultValue(false)]
        public bool isLink { get; set; }
        [DefaultValue(false)]
        public bool isHide { get; set; }
        [DefaultValue(false)]
        public bool isFull { get; set; }
        [DefaultValue(false)]
        public bool isAffix { get; set; }
        public bool isKeepAlive { get; set; }
    }
    public class RuleId
    {
        public int iRuleId {get; set; }
    }
}
